<script lang="ts" setup>
import { onMounted } from 'vue'

defineProps<{
  wave1: string
  wave2: string
  wave3: string
}>()

const getData = () => {
  const box = document.getElementById('box')
  let i = 0
  let timer: any = null
  const loading = () => {
    if (i < 100) {
      i++
      box?.style.setProperty('--per', i + '%')
    } else {
      i = 0
      clearInterval(timer)
      setTimeout(() => {
        box?.style.setProperty('--per', '0%')
        timer = setInterval(loading, 100)
      }, 2000)
    }
  }
  loading()
  timer = setInterval(loading, 100)
}
// 执行
onMounted(() => {
  getData()
})
</script>

<template>
  <div class="box-inner">
    <div class="inner" style="--per: 0%" id="box">
      <!-- 添加svg波浪 -->
      <svg xmlns="http://www.w3.org/2000/svg" version="1.0" viewBox="0 0 600 140" class="box-waves">
        <path d="M 0 70 Q 75 20,150 70 T 300 70 T 450 70 T 600 70 L 600 140 L 0 140 L 0 70Z" />
      </svg>
      <svg xmlns="http://www.w3.org/2000/svg" version="1.0" viewBox="0 0 600 140" class="box-waves">
        <path d="M 0 70 Q 75 20,150 70 T 300 70 T 450 70 T 600 70 L 600 140 L 0 140 L 0 70Z" />
      </svg>
      <svg xmlns="http://www.w3.org/2000/svg" version="1.0" viewBox="0 0 600 140" class="box-waves">
        <path d="M 0 70 Q 75 20,150 70 T 300 70 T 450 70 T 600 70 L 600 140 L 0 140 L 0 70Z" />
      </svg>
    </div>
  </div>
</template>

<style scoped>
:root {
  --wave1: #a0edff;
  --wave2: rgba(40, 187, 255, 0.5);
  --wave3: #2084cc;
}
.box-inner {
  width: 48px;
  height: 48px;
  box-shadow: 0 2px 7px 0 #238fdb;
  border-radius: 50%;
  position: relative;
  border: 2px solid transparent;
  background: linear-gradient(#021f40, #021f40);
  background-origin: border-box;
  background-clip: content-box, border-box;
  /* 溢出隐藏 */
  overflow: hidden;
}
.inner {
  width: 100%;
  height: 100%;
  position: absolute;
  background: #a0edff;
  /* 添加底部距离 */
  bottom: calc(-128% + var(--per));
}
.box-waves {
  position: absolute;
  left: 0;
  bottom: 100%;
  width: 200%;
  stroke: none;
}
.box-waves:nth-child(1) {
  fill: var(--wave1);
  transform: translate(-50%, 0);
  z-index: 3;
  /* svg重合有一条线条，将边距设置为负的 */
  margin-bottom: -2px;
  /* 添加动画 */
  animation: wave-move1 1.5s infinite linear;
}
.box-waves:nth-child(2) {
  fill: var(--wave2);
  transform: translate(0, 0);
  z-index: 2;
  animation: wave-move2 3s infinite linear;
}
.box-waves:nth-child(3) {
  fill: var(--wave3);
  transform: translate(-50%, 0);
  z-index: 1;
  /* 添加动画 */
  animation: wave-move1 3s infinite linear;
}
@keyframes wave-move1 {
  100% {
    transform: translate(0, 0);
  }
}
@keyframes wave-move2 {
  100% {
    transform: translate(-50%, 0);
  }
}
.box-text {
  font-size: 30px;
  font-weight: bold;
  width: 80px;
  text-align: center;
  margin-left: 20px;
  color: #7eedff;
}
*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  padding: 0;
  margin: 0;
}

body {
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #222;
  color: #fff;
  overflow: hidden;
  height: 100vh;
}
</style>
